package mvc;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;




@Controller
public class WebController {
	ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
	DepartmentJDBCTemplate jdbc = (DepartmentJDBCTemplate) context.getBean("departmentJDBCTemplate");
	@RequestMapping(value="/")
	public String index() {
		return "index";
	}
	@RequestMapping(value="/list")
	public String list(ModelMap m) {
		List<Department> list = jdbc.listDepartments();
		m.addAttribute("list", list);
		return "list";
	}
	@RequestMapping(value="/add")
	public String add() {
		return "add";
	}
	@RequestMapping(value="/addData",method = RequestMethod.POST)
	public String addData(Department e) {
		jdbc.create(e.getId(),e.getName(),e.getType(),e.getTelephone(),e.getFax(),e.getDescription(),e.getPredepartment(),e.getDate());
		return "redirect:list";
	}
}
